'use strict'

const { Controller } = require('egg')

class HomeController extends Controller {
  async user() {
    const { ctx } = this
    const data = await ctx.model.User.find({}, 'name').sort({ _id: -1 })
    ctx.body = data.map($ => { return { value: $._id, label: $.name } })
  }

  async action() {
    const { ctx } = this
    const data = await ctx.model.Action.find({}, 'name').sort({ _id: -1 })
    ctx.body = data.map($ => { return { value: $._id, label: $.name } })
  }

  async server() {
    const { ctx } = this
    const data = await ctx.model.Server.find({}, 'name').sort({ _id: -1 })
    ctx.body = data.map($ => { return { value: $._id, label: $.name } })
  }
}

module.exports = HomeController
